import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import createVitePlugins from './vite/plugins'
// https://vite.dev/config/
export default defineConfig(({ mode, command }) => {
  const env = loadEnv(mode, process.cwd());
  const { VITE_APP_ENV } = env;
  return {
    base: VITE_APP_ENV === 'production' ? '/' : '/',
    plugins: createVitePlugins(env, command === 'build'),
    resolve: {
      alias: {
        // 设置路径
        '~': path.resolve(__dirname, './'),
        // 设置别名
        '@': path.resolve(__dirname, './src')
      },
      //自动匹配后缀
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
    },
    // 代理 相关配置
    server: {
      port:7539 ,
      host: true,
      open: true,
      proxy: {
        // https://cn.vitejs.dev/config/#server-proxy
        '/dev-api': {
          // target: 'http://127.0.0.1:4523/m1/6035323-5725142-default',
          target: 'http://127.0.0.1:8000/admin',
          // target: 'http://127.0.0.1:53923/admin',
          // target: 'https://api.lijunxuan.top/admin',
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/dev-api/, '')
        }
      }
    },
    css: {
      preprocessorOptions: {
        //全局scss变量
        scss: {
          additionalData: `@use '@/assets/scssConfig/index.scss' as *;@use '@/assets/styles/common' as *;`,
        },
      }
    }
  }
})
